import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementPlus from 'element-plus'
import '../node_modules/element-plus/theme-chalk/index.css'
import './assets/main.css'
import axios from 'axios'
import mitt from 'mitt'
import VueCookies from "vue-cookies";
import Vuex from 'vuex'




import * as ELIcons from '@element-plus/icons-vue'

const app = createApp(App)

for (let iconName in ELIcons) {
  app.component(iconName, ELIcons[iconName])
}
navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)
// var axios = require('axios')
axios.defaults.baseURL = 'http://1004.website:8777/api'

// app.config.productionTip = false
app.config.globalProperties.$axios = axios
app.config.globalProperties.$bus = new mitt()
app.use(router)
app.use(VueCookies)
app.use(Vuex)

app.use(ElementPlus)

app.use(store),
router.beforeEach((to, from, next) => {
  //查看进入的路径是否要拦截
  if (to.meta.requireAuth) {
    console.log("store.state.user.username" + store.state.user);
    //查看sessionStore有无信息去判断之前是否有登录过
    if (store.state.user) {
      next()
    } else {
      console.log("to.fullPath:" + to.fullPath);
      //没登陆时跳转到登录页面
      next({
        path: 'login',
        query: { redirect: to.fullPath },

      })

    }
  } else {
    next()
  }
},


app.mount('#app')

)